#include "../source/server.hpp"

void OnConnection(const PtrConnect& conn)
{
    DLOG("OnConnection: %p", conn.get());
}

void CloseConnection(const PtrConnect& conn)
{
    DLOG("CloseConnection: %p", conn.get());
}

void OnMessage(const PtrConnect &con, Buffer *buf)
{
    DLOG("%s", buf->GetReaderPos());
    buf->ReadMoveOffset(buf->ReadAbleSize());
    std::string res = "server# Hello tc!";
    con->SendCon(res.c_str(), res.size());
}

int main()
{
    TcpServer tcpserver(8888);
    tcpserver.SetThreadCount(2);
    //tcpserver.EnableInactiveRelease(10);
    tcpserver.SetConnectCallBack(OnConnection);//不需要传递参数，内部已经传递了
    tcpserver.SetCloseCallBack(CloseConnection);
    tcpserver.SetMessageCallBack(OnMessage);
    tcpserver.Start();
    return 0;
}